using NExt.Serialization;

namespace NExt.Core.Validator
{
    public class Regex : ValidatorScript
    {
        private const string FUNCTION_NAME = "Regex";

        private Regex(params string[] parameterNames)
            : base(FUNCTION_NAME, parameterNames)
        {
        }

        public static Regex Create(string message, string pattern, string options)
        {
            string serializedMessage = JsonSerializer.Serialize(message);
            string serializedPattern = JsonSerializer.Serialize(pattern);
            string serializedOptions = JsonSerializer.Serialize(options);
            string parameter = string.Format("{0},{1},{2}", serializedMessage, serializedPattern, serializedOptions);
            Regex regex = new Regex(parameter);
            return regex;
        }

        public static Regex Create(string message, string pattern)
        {
            return Create(message, pattern, null);
        }

        public static Regex Create(string pattern)
        {
            return Create(null, pattern, null);
        }
    }
}